Research
Security News
Malicious npm Package Typosquats react-login-page to Deploy Keylogger
Socket researchers unpack a typosquatting package with malicious code that logs keystrokes and exfiltrates sensitive data to a remote server.
detect-newline
Advanced tools
Package description
The detect-newline npm package is designed to help developers identify the type of newline character used in a string. This can be particularly useful when working with text data that originates from different operating systems, as Unix, Windows, and old Mac systems use different characters for line breaks (`\n` for Unix/Linux, `\r\n` for Windows, and `\r` for old Mac). The package provides a simple interface to detect the newline character and can also gracefully handle mixed or absent newlines.
Detect the most common newline character in a string
This feature allows you to detect the most common newline character in a given string. If the string contains mixed newline characters, the most common one is returned. If there's a tie, `\n` is returned by default.
"const detectNewline = require('detect-newline');\nconst mixedNewlines = 'Hello\r\nWorld\nHello World';\nconsole.log(detectNewline(mixedNewlines)); // '\r\n'"
Detect the newline character used at the end of a string
This functionality is useful for determining the newline character at the end of a string, which can be critical for appending lines to files or data streams while maintaining consistency with the existing newline format.
"const detectNewline = require('detect-newline');\nconst stringWithNewlineAtEnd = 'Hello World\n';\nconsole.log(detectNewline(stringWithNewlineAtEnd)); // '\n'"
Similar to detect-newline, newline-detect also provides functionality for detecting newline characters within strings. The main difference may lie in the implementation details or additional features offered by one package over the other.
The eol package offers more comprehensive handling of newline characters, including detection, conversion, and normalization across different operating systems. While detect-newline focuses on detection, eol provides a broader set of tools for working with end-of-line characters.
Readme
Detect the dominant newline character of a string
$ npm install --save detect-newline
const detectNewline = require('detect-newline');
detectNewline('foo\nbar\nbaz\r\n');
//=> '\n'
Returns detected newline or null
when no newline character is found.
Returns detected newline or \n
when no newline character is found.
MIT © Sindre Sorhus
FAQs
Unknown package
The npm package detect-newline receives a total of 17,918,862 weekly downloads. As such, detect-newline popularity was classified as popular.
We found that detect-newline demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers unpack a typosquatting package with malicious code that logs keystrokes and exfiltrates sensitive data to a remote server.
Security News
The JavaScript community has launched the e18e initiative to improve ecosystem performance by cleaning up dependency trees, speeding up critical parts of the ecosystem, and documenting lighter alternatives to established tools.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.